<template>
  <div class="wrapper">
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      selectionType="multiple"
      :datakey="'rows'"
      :isColumnFilter="false"
      :isToperInfo="false"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="columns => (this.columns = columns)"
    >
    </FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDialog">取 消</el-button>
      <el-button type="primary" @click="saveDialog">确 定</el-button>
      <!-- :loading="addBtnState" -->
    </div>
    <BaseDialog :visible.sync="showAddNew" title="服务活动明细" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <FwhdMx :rowsData="rowsData" @close="closeBaseDialog" />
    </BaseDialog>
  </div>
</template>
<script>
// import { mapState } from 'vuex';
import { getFwhdList, getFwhdQdWxxmList, getFwhdQdWxclList, getFwhdQdfjxmList } from '@/api/repair/business/customer/activity.js';
import { dictionary } from '@/utils/dictMixin';
import FwhdMx from './fwhdmx';
export default {
  name: 'activity',
  components: {
    FwhdMx
  },
  mixins: [dictionary],
  props: ['actData', 'repirlist'],
  data() {
    // this.BaseTable = null;
    return {
      fetchApi: getFwhdList,
      fetchParams: this.actData,
      columns: this.createTableColumns(),
      showAddNew: false,
      rowsData: null,
      saveData: [],
      obj: [],
      params: {
        res1: '',
        res2: '',
        res3: ''
      }
    };
  },
  computed: {
    // ...mapState('app', ['btnLoading']),
    // addBtnState() {
    //   return this.btnLoading[types.YAN_ROLE_ADD];
    // }
  },
  methods: {
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '明细',
          dataIndex: '',
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.detail(props.row)}>
                  明细
                </el-button>
              </div>
            );
          }
        },
        {
          title: '存在',
          dataIndex: 'IS_EXIST',
          sorter: true
        },
        {
          title: '活动编号',
          dataIndex: 'ACTIVITY_CODE',
          sorter: true
        },
        {
          title: '活动名称',
          dataIndex: 'ACTIVITY_NAME',
          sorter: true
        },
        {
          title: '活动类型',
          dataIndex: 'ACTIVITY_TYPE',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.ACTIVITY_TYPE, '1184')}</span>;
          }
        },
        {
          title: '开始日期',
          dataIndex: 'BEGIN_DATE',
          dateFormat: 'yyyy-MM-dd',
          sorter: true
        },
        {
          title: '结束日期',
          dataIndex: 'END_DATE',
          dateFormat: 'yyyy-MM-dd',
          sorter: true
        },
        {
          title: '活动总金额',
          dataIndex: 'ACTIVITY_AMOUNT',
          sorter: true
        }
      ];
    },
    closeDialog() {
      this.$emit('close1', false);
    },
    closeBaseDialog(val) {
      this.showAddNew = val;
    },
    detail(data) {
      this.showAddNew = true;
      console.log(data);
      this.rowsData = data;
    },
    selectChangeHandle(rows) {
      if (!rows.length) {
        return;
      }
      this.saveData = rows;
    },
    async getFwhdQdWxxmList(row) {
      const res = await getFwhdQdWxxmList(row);
      this.params.res1 = res;
    },
    async getFwhdQdWxclList(row) {
      const res = await getFwhdQdWxclList(row);
      this.params.res2 = res;
    },
    async getFwhdQdfjxmList(row) {
      const res = await getFwhdQdfjxmList(row);
      this.params.res3 = res;
    },
    async saveDialog() {
      this.saveData.forEach(x => {
        this.obj.push(`'${x.ACTIVITY_CODE}'`);
      });
      let flag = false;
      let reg = this.saveData;
      let arr = [...this.repirlist];
      console.log(reg, arr, '11');
      if (arr && arr.length > 0) {
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < reg.length; j++) {
            if (arr[i].ACTIVITY_CODE == reg[j].ACTIVITY_CODE) {
              flag = true;
              break;
            }
          }
        }
      }
      if (flag) {
        alert('相同');
      } else {
        await this.getFwhdQdWxxmList(this.obj.join());
        await this.getFwhdQdWxclList(this.obj.join());
        await this.getFwhdQdfjxmList(this.obj.join());
        this.$emit('ReceiveData', this.params);
        console.log('传给客户代', this.params);
      }
    }
  }
};
</script>
<style lang="less" scoped>
.wrapper {
  height: calc(100vh - 135px);
}
</style>
